package org.echarts.servlet;

import org.codehaus.jackson.map.ObjectMapper;
import org.echarts.bean.Point;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

/**
 * 获取基站坐标数量
 * Created by Administrator on 2017/1/24.
 */
@WebServlet(name="GetPointsCount", urlPatterns = {"/getPointsCount"})
public class GetPointsCount extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String counts = "0";

        Connection con = null;
        PreparedStatement ps = null;
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
            con = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orclgbk", "huaat_bigdata", "huaat_bigdata");
            ps = con.prepareStatement("SELECT COUNT(*) AS COUNTS FROM TB_B_STATION");
            ResultSet rs = ps.executeQuery();

            while (rs.next()){
                counts = rs.getString("COUNTS");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                ps.close();
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        System.out.println(counts);

        // 返回
        PrintWriter out = resp.getWriter();
        out.print(counts);
    }
}
